<template>
  <div class="card">
    <div class="card-header">最新资源</div>
    <div class="card-content card-list">
      <div
        v-for="doc in curSpace.recentDocuments"
        :key="doc.id"
        class="flex card-list-item align-items-center"
      >
        <el-image v-if="doc.img" :src="uploadIcon(doc.img)" class="s15 m-r-5" />
        <router-link
          :to="initDocUrl(doc)"
          class="flex-1 link no-warp-ellipsis"
          :title="doc.title"
          v-text="doc.title"
        />
        <timeago2 class="shrink-0 m-l-10" :date-time="doc.updated_at"/>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
import FileIconMixin from '@/utils/file-icon-mixin';

export default {
  name: 'RecentDocuments', // 最新资源
  mixins: [FileIconMixin],
  computed: {
    ...mapState({ curSpace: 'currentSpace' }),
  },
  methods: {
    initDocUrl(doc) {
      if (doc.type === 'ProductSnippet') return `/spaces/${this.curSpace.id}/resources-docs/${doc.id}`;
      return `/spaces/${this.curSpace.id}/resources-uploads/${doc.id}`;
    },
  },
};
</script>

<style></style>
